﻿using System;
using System.Collections.Generic;
using System.Text;
using PokemonBattle.PokemonData.Util;

namespace PokemonBattle.PokemonData.SQLite.DAL
{
    public static class DALHiddenPower
    {
        /// <summary>
        /// 根据属性名称返回觉醒力量IV
        /// </summary>
        public static Base6D GetHiddenIv(string name)
        {
            const string sql = "select v.[Hp],v.[Atk],v.[Def],v.[SpA],v.[SpD],v.[Spe] from v_hiddentype v where v.[Name] like '%{0}%' or v.[EnName] like '%{0}%' limit 1";
            var dt = DbHelperSQLite.ExecuteDataTable(string.Format(sql, name.Trim().ToLower()));
            if (dt != null && dt.Rows.Count > 0)
            {
                var b = new Base6D(0);
                var dr = dt.Rows[0];
                b.Hp = dr[0].ToString().ToInt();
                b.Atk = dr[1].ToString().ToInt();
                b.Def = dr[2].ToString().ToInt();
                b.SpAtk = dr[3].ToString().ToInt();
                b.SpDef = dr[4].ToString().ToInt();
                b.Speed = dr[5].ToString().ToInt();
                return b;
            }
            return null;
        }

        /// <summary>
        /// 根据TypeId返回觉醒力量IV
        /// </summary>
        public static Base6D GetHiddenIv(int id)
        {
            const string sql = "select v.[Hp],v.[Atk],v.[Def],v.[SpA],v.[SpD],v.[Spe] from v_hiddentype v where v.typeid ={0} limit 1";
            var dt = DbHelperSQLite.ExecuteDataTable(string.Format(sql, id));
            if (dt != null && dt.Rows.Count > 0)
            {
                var b = new Base6D(0);
                var dr = dt.Rows[0];
                b.Hp = dr[0].ToString().ToInt();
                b.Atk = dr[1].ToString().ToInt();
                b.Def = dr[2].ToString().ToInt();
                b.SpAtk = dr[3].ToString().ToInt();
                b.SpDef = dr[4].ToString().ToInt();
                b.Speed = dr[5].ToString().ToInt();
                return b;
            }
            return null;
        }
    }
}
